import java.util.*;

class Contact{
	String Name;
	String Phone;
	String note;
	
	
}

public class PB implements Iterable, Iterator {

	//Map<PhoneBookName> Map1;

	Map<String, Contact> contactByName = new TreeMap<String, Contact>();
	Map<String, Contact> contactByPhone = new TreeMap<String, Contact>();

	public boolean add(Contact New){

		if (contactByName.containsKey(New.Name)){
			return false;
		}
		else {
			contactByName.put(New.Name,New);
			contactByPhone.put(New.Phone,New);
			return true;
		}
	}

	public Contact getByName(String Name){
		return contactByName.get(Name);
	}
	
	public Contact getByPhone(String Phone){
		return contactByPhone.get(Phone);
	}
	
	
	@Override
	public boolean hasNext() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Object next() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void remove() {
		// TODO Auto-generated method stub
		
	}

	public Iterator<Contact> sortedByNameIterator() {
		// TODO Auto-generated method stub
		//Set<String> n = contactByName.keySet();
		//return  (Iterator<Contact>) contactByName.entrySet();
		return  contactByName.values().iterator();
		//return null;
	}

	public Iterator<Contact> sortedByPhoneIterator() {
		// TODO Auto-generated method stub
		//Set<String> n = contactByName.keySet();
		//return  (Iterator<Contact>) contactByPhone.entrySet();
		return  contactByPhone.values().iterator();
		//return null;
	}

	@Override
	public Iterator iterator() {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		PB imp = new PB();
		
		Contact a = new Contact();
		Contact b = new Contact();
		a.Name="Georgi";
		a.Phone="123";
		b.Name="Niki";
		b.Phone="456";
		
		imp.add(a);
		imp.add(b);
		
		Iterator it=imp.sortedByNameIterator();
		
	}

	
}
